package zzz.jsondemo;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

/**
 * Created by 隼 on 2017/5/17.
 * 解析json
 */

public class GsonRead {
    public static void main(String[] args) throws IOException {
        day();

    }
    //解析json
    private static void Fjson() throws IOException {
        File file=new File("I:\\MyIDEACeit\\SpringmvcDemo\\src\\main\\java\\zzz\\jsondemo\\test.json");
        String content= FileUtils.readFileToString(file);
        Gson gson=new Gson();
        Diaosi test=gson.fromJson(content,Diaosi.class);
        System.out.println(test.toString());
    }


    //带日期类型的
    private  static void day() throws IOException {
        File file=new File("I:\\MyIDEACeit\\SpringmvcDemo\\src\\main\\java\\zzz\\jsondemo\\test.json");
        String content= FileUtils.readFileToString(file);
        Gson gson=new GsonBuilder().setDateFormat("yyy-MM-dd").create();
        diaod test=gson.fromJson(content,diaod.class);
        System.out.println(test.getBirthday().toLocaleString());
        System.out.println(test.getMajor());
        System.out.println(test.getMajor().getClass());
        System.out.println(test.getAge());
    }





}
